package com.study.compose.beta.view

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.module.compose.base.composable.CodeView
import com.module.compose.base.composable.Content
import com.module.compose.base.composable.ContentView
import com.module.compose.base.composable.Title
import com.study.compose.beta.theme.RandomColor

/**
 * 文字控件的使用示例
 */
@Composable
fun TextSample() {
    LazyColumn(
        Modifier
            .fillMaxSize()
            .padding(start = 15.dp, end = 15.dp)
    ) {
        item {
            Column {
                ContentView {
                    Title(title = "Text控件用来展示文本，具有以下属性：")
                    Content(
                        content =
                        """
                        设置文字
                        text: String,
                        设置属性（宽高、边距等）
                        modifier: Modifier = Modifier,
                        设置文字颜色
                        color: Color = Color.Unspecified,
                        设置文字大小
                        fontSize: TextUnit = TextUnit.Unspecified,
                        设置文字斜体展示
                        fontStyle: FontStyle? = null,
                        设置字体加粗效果
                        fontWeight: FontWeight? = null,
                        设置字体使用的字体
                        fontFamily: FontFamily? = null,
                        设置每个字符的间距，单位：.sp
                        letterSpacing: TextUnit = TextUnit.Unspecified,
                        设置下划线
                        textDecoration: TextDecoration? = null,
                        设置文字的展示效果，居左、居右等
                        textAlign: TextAlign? = null,
                        文字的行高，单位：.sp
                        lineHeight: TextUnit = TextUnit.Unspecified,
                        设置文字溢出的效果
                        overflow: TextOverflow = TextOverflow.Clip,
                        暂不清楚
                        softWrap: Boolean = true,
                        最大行数
                        maxLines: Int = Int.MAX_VALUE,
                        暂不清楚
                        onTextLayout: (TextLayoutResult) -> Unit = {},
                        设置文字样式，可以直接使用属性进行设置
                        style: TextStyle = LocalTextStyle.current
                        
                        """.trimIndent()
                    )
                }

                Text(
                    text = "展示一行简单的文字",
                    color = RandomColor.color(),
                    fontStyle = FontStyle.Italic,
                    fontSize = 25.sp
                )
                CodeView(
                    code =
                    """
                    Text(
                        text = "展示一行简单的文字",
                        color = Color.Blue,
                        fontStyle = FontStyle.Italic
                        fontSize = 25.sp
                    )
                    """.trimIndent()
                )
                Text(
                    text = "Text with FontFamily",
                    fontFamily = FontFamily.Cursive,
                    color = RandomColor.color(),
                    fontSize = 25.sp
                )
                CodeView(
                    code =
                    """
                    Text(
                        text = "Text with FontFamily",
                        fontFamily = FontFamily.Cursive,
                        color = TextBlack,
                        fontSize = 25.sp
                    )
                    """.trimIndent()
                )
                Text(
                    text = "带下划线的文字",
                    color = RandomColor.color(),
                    fontSize = 25.sp,
                    textDecoration = TextDecoration.Underline
                )
                CodeView(
                    code =
                    """
                    Text(
                        text = "带下划线的文字",
                        color = RandomColor.color(),
                        fontSize = 25.sp,
                        textDecoration = TextDecoration.Underline
                    )   
                    """.trimIndent()
                )
                Text(
                    text = "加粗效果的文字",
                    color = RandomColor.color(),
                    fontSize = 25.sp,
                    textDecoration = TextDecoration.combine(
                        listOf(
                            TextDecoration.LineThrough,
                            TextDecoration.Underline
                        )
                    ),
                    fontWeight = FontWeight.Bold
                )
                CodeView(
                    code =
                    """
                    Text(
                        text = "加粗效果的文字",
                        color = RandomColor.color(),
                        fontSize = 25.sp,
                        textDecoration = TextDecoration.combine(
                            listOf(
                                TextDecoration.LineThrough,
                                TextDecoration.Underline
                            )
                        ),
                        fontWeight = FontWeight.Bold
                    )  
                    """.trimIndent()
                )
            }
        }
    }
}